﻿Public MustInherit Class FileMng

    Public Property strErrorMsg As String

    ''' <summary>
    ''' Clear all class info
    ''' </summary>
    Public MustOverride Sub Clear()

    ''' <summary>
    ''' Read file and store info in the class
    ''' </summary>
    Public MustOverride Function ReadFile(ByRef inText() As String) As Boolean

    ''' <summary>
    ''' Save stored info in a file
    ''' </summary>
    Public MustOverride Function SaveFile(ByVal inFilePath As String) As Boolean

    ''' <summary>
    ''' Read source file generating info to store in the class
    ''' </summary>
    Public MustOverride Function ReadSourceFile(ByRef inText() As String) As Boolean

    ''' <summary>
    ''' Generate file in a string using stored info
    ''' </summary>
    Public MustOverride Function GenerateFile(ByRef outFile As String) As Boolean

    ''' <summary>
    ''' Clean string removing tabs and spaces
    ''' </summary>
    Protected Function CleanString(ByVal inText As String) As String
        Dim intPosition As Integer = inText.IndexOf(vbTab)

        While intPosition > -1
            inText = inText.Remove(intPosition, 1)
            intPosition = inText.IndexOf(vbTab)
        End While

        Return Trim(inText)
    End Function

    ''' <summary>
    ''' Get name and value of attribute
    ''' </summary>
    Protected Function SplitAttribute(ByVal inLine As String, ByVal inSep As String, ByRef outName As String, ByRef outValue As String) As Boolean
        Dim vettSplit() As String = Split(inLine, inSep)

        If vettSplit.Count = 2 Then
            outName = vettSplit(0)
            outValue = vettSplit(1)
            Return True
        Else
            Return False
        End If
    End Function

End Class
